package com.example.zzm.yuejian03.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.zzm.yuejian03.Activity.ClubActivity;
import com.example.zzm.yuejian03.Activity.TraindetailsActivity;
import com.example.zzm.yuejian03.Bean.SousuoBean;
import com.example.zzm.yuejian03.R;

import java.util.List;

public class sousuoAdapter extends RecyclerView.Adapter<sousuoAdapter.ViewHolder>{

    private List<SousuoBean> mSearch;
    private Context mContext;
    mOnItemClickListener mOnItemClickListener;

    public sousuoAdapter(Context mContext, List<SousuoBean> mSearch){
        this.mContext = mContext;
        this.mSearch = mSearch;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public sousuoAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.sousuoadapter ,parent,false);
        sousuoAdapter.ViewHolder holder = new sousuoAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final sousuoAdapter.ViewHolder holder, final int position) {
        final SousuoBean search = mSearch.get(position);
        if(search.getFlag()==1){
            holder.search_intro.setText(search.getClub_name());
        }else if( search.getFlag()==2){
            holder.search_intro.setText(search.getTrain_name());
        }

        holder.search_intro.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(search.getFlag()==1){
                    Intent intent = new Intent(mContext, ClubActivity.class);
                    intent.putExtra("club_id",search.getClub_id());
                    mContext.startActivity(intent);
                }else if( search.getFlag()==2){
                    Intent intent = new Intent(mContext, TraindetailsActivity.class);
                    intent.putExtra("train_id",search.getTrain_id());
                    mContext.startActivity(intent);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return mSearch.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView search_intro;
        public ViewHolder(View view){
            super(view);
            search_intro = (TextView)view.findViewById(R.id.search_intro);
        }
    }


    public interface mOnItemClickListener {
        void onClick(View view, int position);
    }

    public void setmOnItemClickListener(sousuoAdapter.mOnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }
}
